package edu.jvn.ict.locationsharing;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class LocationSharing extends Activity implements OnClickListener {
	public static final int JOIN = 0;
	public static final int START = 1;

	public static String phoneNumber;
	public static int port;
	public static int option;

	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		setContentView(R.layout.login);

		Button loginButton = (Button) findViewById(R.id.joinButton);
		loginButton.setOnClickListener(this);

		Button createButton = (Button) findViewById(R.id.createButton);
		createButton.setOnClickListener(this);
	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub

		EditText phoneInput = (EditText) findViewById(R.id.inputPhone);
		EditText portInput = (EditText) findViewById(R.id.inputPort);
		String phoneNumberTemp = (String) phoneInput.getText().toString();
		int portTemp = Integer.parseInt(portInput.getText().toString());
		try {
			phoneNumber = phoneNumberTemp;
			port = portTemp;
			switch (v.getId()) {
			case R.id.joinButton:
				option = JOIN;
				break;
			case R.id.createButton:
				option = START;
				break;
			}
			goOnlinePage();
		} catch (Exception e) {
			Toast.makeText(this, "Please input a phone number",
					Toast.LENGTH_SHORT);
		}
	}

	public void goOnlinePage() {
		this.finish();
		startActivity(new Intent(this, LocationSharingRun.class));
	}
	
}